package ToYesterday.Day05;


import java.io.*;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */


class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}

public class sortLinkList {

    public static ListNode sortList(ListNode head) {
        ListNode dummp = new ListNode(-10000);
        dummp.next = head;
        ListNode nodeCurrent = dummp;
        ListNode nodePre = dummp;
        ListNode nodewhile =dummp;
        while (nodeCurrent.next!=null){
            nodePre = nodeCurrent;
            nodeCurrent=nodeCurrent.next;
            if (nodeCurrent.val< nodePre.val){
                nodewhile = dummp;
                while (nodewhile.next!=null){
                    if (nodewhile.next.val> nodeCurrent.val){
                        nodePre.next = nodePre.next.next;
                        nodeCurrent.next=nodewhile.next;
                        nodewhile.next=nodeCurrent;
                        nodeCurrent=nodePre;
                        break;
                    }
                    nodewhile=nodewhile.next;
                }
            }
        }
        return dummp.next;
    }


    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new FileReader("E:\\Users\\wuxiaoxuan\\IdeaProjects\\Algorithm\\src\\Day04\\num.txt"));//打开文件创建数据流
        String str;
        String [] s = new String[30294];
        while((str=in.readLine())!=null){
            s=str.split(",|\\[|\\]");
            System.out.println(s.length);
        }
        int[] strd = new int[30294];
        for (int i=0;i<s.length;i++){
            strd[i] = Integer.parseInt(s[i]);
        }
        sort(strd,0,s.length);
        for (int i :strd){
            System.out.println(i);
        }



//        //这里是初始化链表排序
//        ListNode p = new ListNode(-1);
//        ListNode q = p;
//        for (int i = 1;i<s.length;i++){
//            ListNode x = new ListNode(Integer.parseInt(s[i]));
//            q.next=x;
//            q=x;
//        }
//        ListNode z = sortList(p);
//        while (z!=null){
//            System.out.println(z.val);
//            z=z.next;
//        }







//        while (p!=null){
//            System.out.println(p.val);
//            p=p.next;
//        }
//        ListNode p1 = new ListNode(4);
//        ListNode p2 = new ListNode(2);
//        ListNode p3 = new ListNode(1);
//        ListNode p4 = new ListNode(3);
//        ListNode p5 = new ListNode(5);
//        p1.next = p2;
//        p2.next = p3;
//        p3.next = p4;
//        p4.next = p5;
//

    }


    static int pati(int[] str, int low, int high){
        int temp =str[low];
        while (low<high){
            if (str[high]<temp){
                str[low]=str[high];
                low++;
            }else {
                high--;
                continue;
            }
            if (str[low]>temp){
                str[high]=str[low];
                high--;
            }else {
                low++;
                continue;
            }
        }
        str[low]=temp;
        return low;
    }

    static void sort(int[] str, int low, int high){
        int pai = pati(str,low,high);
        sort(str,low,pai-1);
        sort(str,pai+1,high);
    }
}
